package org.jeecg.modules.shiro.authc.aop;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyHandlerInterceptorAdapter extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request , HttpServletResponse response , Object handler) {
        try {
            Subject subject = SecurityUtils.getSubject();
            if (subject != null) {
                LoginUser loginUser = (LoginUser) subject.getPrincipal();
                if (loginUser != null) {
                    response.setHeader("token", loginUser.getActiveToken());
                }
            }
        }catch (Exception e){
        }
        return true;
    }
}